<!DOCTYPE html> 
<html lang="zh-cmn-Hans"> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0"> 
    <title>商家定位</title>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=wDYEcxgRRheZwyC9jpN1Tt7fzr2zjosZ"></script>   
    <script src="../js/jquery-1.10.1.min.js"></script><!--调用jQuery-->
</head> 
   
<body>   
   <div id="allmap"></div> 
</body>   
</html>
<script type="text/javascript">
    function getItem(name){
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) return unescape(arr[2]); return null;
    }
    var shop = JSON.parse(getItem('shopAddress'));
    console.log(shop);
    var shopName = shop.name;
    var shopAddress = shop.detail;
    var shopPhone = shop.phone;
    var lnt = shop.lnt;
    var lat=lnt.split(",")[0];
    var lng=lnt.split(",")[1]
    console.log(lnt);
    var map = new BMap.Map("allmap");
    //console.log(shopAddress);
    var point = new BMap.Point(lng,lat);
    map.centerAndZoom(point, 16);
    map.enableScrollWheelZoom();  
   
    var myIcon = new BMap.Icon("../img/baidu-map.png",new BMap.Size(30,30),{
        anchor: new BMap.Size(10,10)     
    }); 
   
    var marker=new BMap.Marker(point,{icon: myIcon});   
    map.addOverlay(marker);   
   
    var geolocation = new BMap.Geolocation(); 
    geolocation.getCurrentPosition(function(r){ 
        if(this.getStatus() == BMAP_STATUS_SUCCESS){ 
            var mk = new BMap.Marker(r.point); 
            map.addOverlay(mk); 
            //map.panTo(r.point);//地图中心点移到当前位置 
            var latCurrent = r.point.lat; 
            var lngCurrent = r.point.lng; 
            //alert('我的位置：'+ latCurrent + ',' + lngCurrent); 

            location.href="http://api.map.baidu.com/direction?origin="+latCurrent+","+lngCurrent+"&destination="+lnt+"&mode=driving&region=郑州&output=html";

        } 
        else { 
            alert('failed'+this.getStatus()); 
        }         
    },{enableHighAccuracy: true}) 
   
   
    map.addOverlay(marker);   
    var licontent="<b>"+shopName+"</b><br>";
        licontent+="<span><strong>地址：</strong>"+shopAddress+"</span><br>";
        licontent+="<span><strong>电话：</strong>"+shopPhone+"</span><br>";
    var opts = {  
        width : 200, 
        height: 100,
    };          
    var  infoWindow = new BMap.InfoWindow(licontent, opts);   
    marker.openInfoWindow(infoWindow);   
    marker.addEventListener('click',function(){ 
        marker.openInfoWindow(infoWindow); 
    });   
   
</script> 